package com.hdu.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class StudentInvocationHandler implements InvocationHandler {

    private final Object targetObject;
    private final static String METHOD_SAVE = "save";

    public StudentInvocationHandler(Object targetObject) {
        this.targetObject = targetObject;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if (METHOD_SAVE.equals(method.getName())) {
            System.out.println("before save");
            Object result = method.invoke(targetObject, args);
            System.out.println("after save");
            return result;
        }
        else {
            return method.invoke(targetObject, args);
        }
    }
}
